<template>
	<view style="padding-bottom: 16rpx;">
		<view class="exam-list fx-center" v-for="(item,index) in list" :key="item.id" v-if="list.length>0"
			@click="toDetail(item)">
			<image :src="item.cover_url" mode="aspectFill" class="exam-left-img"></image>
			<view class="exam-right">
				<view class="main-basic-name">{{item.name}}</view>
				<view class="exam-process">考核进度：{{item.done}}/{{item.total}}</view>
				<view class="exam-status">
					<view :class="item.state === 1 ? 'color1' : item.state === 2 ? 'color2' :'color3'">
						{{item.state_name}}
					</view>
					<!-- <view class="color2">已提交正在审核</view>
					<view class="color3">已通过</view> -->
				</view>
				<view class="fx-content-end" v-if="item.state!==3">
					<image src="/static/stop_exam.png" mode="widthFix" class="stop-exam"
						@click.stop="stopExam(item.id)"></image>
				</view>

			</view>
		</view>
		<view class="empty-box" v-else>
			<image src="/static/empty_img.png" mode="widthFix"></image>
			<view class="">暂无考核项目</view>
		</view>
		<c-center-dialog ref="tipRef" comfirmText="终止考核" cancelText="返回" @comfirm="dialogComfirm">
			<template>
				<view class="">终止考核将清除所有学习数据，并移出列表，确定终止吗？</view>
			</template>
		</c-center-dialog>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				examId: ''
			};
		},
		onLoad() {
			this.getList()
		},
		onPullDownRefresh() {
			this.getList()
			setTimeout(() => {
				uni.stopPullDownRefresh()
			}, 1500)
		},
		methods: {
			getList() {
				this.$api.requst(`/gwc/user/projects`, {}).then((res) => {
					this.list = res.data
					if (this.list.length <= 0) {
						uni.setNavigationBarColor({
							backgroundColor: '#ffffff',
							frontColor: '#000000'
						})
					}
				})
			},
			stopExam(id) {
				this.examId = id
				this.$refs.tipRef.show()
			},
			dialogComfirm() {
				this.$api.requst(`/gwc/user/projects/cancel`, {
						id: this.examId
					}, 'POST')
					.then((res) => {
						this.$api.showError('提交成功！')
						this.$refs.tipRef.close()
						setTimeout(() => {
							this.getList()
						}, 500)
					})

			},
			toDetail(item) {
				if (item.done === item.total) {
					uni.navigateTo({
						url: '/pages/workbench/trainCourse/learnResult/learnResult?pid=' + item.project_id +
							"&state=" + item.state
					})
				} else {
					uni.navigateTo({
						url: '/pages/workbench/trainCourse/trainCourse?id=' + item.project_id
					})
				}

			}
		}
	}
</script>

<style lang="scss">
	.exam-list {
		padding: 32rpx;
		margin: 16rpx 24rpx 0;
		border-radius: 4rpx 4rpx 4rpx 4rpx;
		background: #FFFFFF;

		.exam-left-img {
			width: 180rpx;
			height: 180rpx;
			border-radius: 4rpx 4rpx 4rpx 4rpx;
			margin-right: 32rpx;
			flex-shrink: 0;
		}

		.exam-right {
			flex: 1;

			.exam-process {
				font-size: 26rpx;
				color: #5C5F66;
				margin-top: 16rpx;
			}

			.exam-status {
				margin-top: 32rpx;
				font-size: 26rpx;
				display: flex;
				justify-content: space-between;


			}

			.stop-exam {
				width: 64rpx;
				height: 40rpx;
			}

			.color1 {
				color: #4078E5;
			}

			.color2 {
				color: #FF5C00;
			}

			.color3 {
				color: #8A8F99;
			}
		}
	}

	.empty-box {
		font-size: 26rpx;
		color: #BEBFC2;
		min-height: 100vh;
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-top: 50%;
		box-sizing: border-box;
		background-color: #fff;

		image {
			width: 320rpx;
			height: 320rpx;
		}
	}
</style>